﻿using FlexFlow.Model;
using FlexFlow.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FlexFlow.MVC.Controllers
{
    [Auth(AuthType.API)]
    public class NotificationAPIController : Controller
    {
        /// <summary>
        /// 取得当前登录用户的通知文件夹列表
        /// </summary>
        /// <param name="limit">
        /// 要取得的文件夹数量
        /// </param>
        /// <param name="allCount">
        /// 用户通知文件夹总数量
        /// </param>
        /// <returns>
        /// 操作结果
        /// </returns>
        public ActionResult GetUserCatalogs(int limit = 4)
        {
            long allCount = 0;
            var user = DefaultComponentSettings.OnlineUserPool.GetLoginedUserInfo(Request);
            if (user == null)
            {
                return Json(
                    new OperateResult()
                    {
                        ResultCode = 403,
                        Message = "拒绝访问"
                    }
                );
            }
            OperateResult res = NotificationManager.Default.GetUserCatalogs(user.UserId, limit, out allCount);
            if (res.ResultCode == 200)
            {
                res.Tag = new
                {
                    count = allCount,
                    data = res.Tag
                };
            }

            return Json(res, JsonRequestBehavior.AllowGet);
        }
    }
}
